import axios from 'axios'
import { store } from '@/redux/store.js' 
import {
	change_loading
} from "@/redux/reducres/collapsend.js";

const request = axios
request.defaults.baseURL = "http://localhost:5000"
request.interceptors.request.use(function (config) {
	store.dispatch(change_loading(true))
	return config;
}, function (error) {
	// Do something with request error
	return Promise.reject(error);
});

// Add a response interceptor
request.interceptors.response.use(function (response) {
	// Any status code that lie within the range of 2xx cause this function to trigger
	// Do something with response data

	store.dispatch(change_loading(false))
	//隐藏loading
	return response;
}, function (error) {
	// Any status codes that falls outside the range of 2xx cause this function to trigger
	// Do something with response error
	store.dispatch(change_loading(false))

	//隐藏loading
	return Promise.reject(error);
});
export default request